using System;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using System.Threading;
using Beetle;

internal class i
{
	private Queue<aq> m_a = new Queue<aq>(1024);

	private aq m_b;

	private bool m_c;

	public i()
	{
		WaitCallback callBack = delegate
		{
			d();
		};
		ThreadPool.QueueUserWorkItem(callBack);
	}

	public void a(aq A_0)
	{
		lock (this.m_a)
		{
			this.m_a.Enqueue(A_0);
		}
	}

	[SpecialName]
	public int c()
	{
		return this.m_a.Count;
	}

	protected aq a()
	{
		lock (this.m_a)
		{
			if (this.m_a.Count > 0)
			{
				return this.m_a.Dequeue();
			}
			return null;
		}
	}

	protected virtual void b()
	{
		this.m_b = a();
		if (this.m_b != null)
		{
			try
			{
				if (!this.m_b.aq)
				{
					try
					{
						this.m_b.d();
						return;
					}
					catch (Exception exception)
					{
						this.m_b.InvokeChannelError(new ChannelErrorEventArgs
						{
							Channel = this.m_b,
							Exception = exception
						});
						return;
					}
				}
				return;
			}
			catch
			{
				return;
			}
		}
		Thread.Sleep(TcpUtils.SocketDespatchSleepTime);
	}

	public virtual void d()
	{
		if (!TcpUtils.ExecutionContext)
		{
			ExecutionContext.SuppressFlow();
		}
		while (!this.m_c)
		{
			b();
		}
	}

	public void e()
	{
		lock (this)
		{
			if (!this.m_c)
			{
				while (this.m_a.Count > 0)
				{
					aq aq2 = this.m_a.Dequeue();
					aq2.j = "receive despatch close!";
					aq2.Dispose();
				}
				this.m_c = true;
			}
		}
	}

	[CompilerGenerated]
	private void a(object A_0)
	{
		d();
	}
}
